#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#define BUFFSIZE 1024
int main(int argc, char* argv[]){
    if(argc < 3){
        printf("Usage: %s <source> <destination>\n", argv[0]);
        return -1;
    }

    int fds = open(argv[1], O_RDONLY);
    if(fds < 0){
        perror("open src failed");
        return -1;
    }

    int fdd = open(argv[2], O_WRONLY | O_CREAT, 0644);
    if(fdd < 0){
        perror("open dst failed");
        close(fds);
        return -1;
    }

    char buf[BUFFSIZE];
    int read_len = 0;
    while((read_len = read(fds, buf, BUFFSIZE)) > 0){
        write(fdd, buf, read_len);
    }

    close(fds);
    close(fdd);

    return 0;
}